﻿/*
 *  Source code courtesy of the desktopWeb.CodePlex.com community project. See MS-PL license on Codeplex.com. 
 *  This is beta code not intended for a production application.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using MyData.WordAddIn.SampleWorkflow;
using MyData.Common;
using Microsoft.Office.Tools;

namespace MyData.WordAddIn
{
  public partial class WorkflowRibbon
  {
    private WorkflowConfiguration config = new WorkflowConfiguration();

    private CustomTaskPane _taskPane;
    public CustomTaskPane TaskPane
    {
      get
      {
        return _taskPane;
      }
      set
      {
        _taskPane = value;
      }
    }

    private void runSplitButton_Click(object sender, RibbonControlEventArgs e)
    {
      this.ShowActivitiesCTP();
      IClientActivity sampleActivity = new SampleActivity();
      sampleActivity.Run(config.DefaultWorkflow);
    }

    private void ShowActivitiesCTP()
    {
      Globals.ThisAddIn.Application.Documents.Open(config.GetAppSetting("SampleDocument"));      
      if (TaskPane == null)
      {
        TaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(new WorkflowActivitiesControl(), "Workflow Activities");
        TaskPane.Visible = true;
      }
    }

    private void configurationButton_Click(object sender, RibbonControlEventArgs e)
    {
      ConfigurationPropertyGrid configForm = new ConfigurationPropertyGrid();
      configForm.ShowDialog();
    }

    private void designButton_Click(object sender, RibbonControlEventArgs e)
    {
      WorkflowDesignerForm designerForm = new WorkflowDesignerForm();
      designerForm.workflowDesignerControl1.Load(config.DefaultWorkflow);
      //- designerForm.Show(new MyWin32Window(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle));
      designerForm.ShowDialog();

      this.ShowActivitiesCTP();
    }
  }
}
